package org.JWCB.system.controller.question;

import org.JWCB.common.core.controller.BaseController;
import org.JWCB.common.file.domain.OSSResult;
import org.JWCB.system.domain.question.dto.QuestionAddDto;
import org.JWCB.system.domain.question.dto.QuestionEditDto;
import org.JWCB.system.domain.question.dto.QuestionQueryDto;
import org.JWCB.system.domain.question.vo.QuestionDetailVo;
import org.JWCB.common.core.domain.vo.R;
import org.JWCB.common.core.domain.vo.TableDataInfo;
import org.JWCB.system.domain.question.vo.QuestionTagVo;
import org.JWCB.system.service.file.IFileService;
import org.JWCB.system.service.question.IQuestionService;
import org.JWCB.system.service.question.IQuestionTagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("question")
public class QuestionController extends BaseController {
    @Autowired
    private IQuestionService questionService;


    @Autowired
    private IQuestionTagService questionTagService;

    @Autowired
    private IFileService fileService;
    @GetMapping("/list")
    public TableDataInfo list(@Validated QuestionQueryDto questionQueryDto) {

        return getTableList(questionService.list(questionQueryDto));
    }


    @PostMapping("/add")
    public R<Void> add(@RequestBody @Validated QuestionAddDto questionAddDto) {
        return toR(questionService.add(questionAddDto));
    }



    @GetMapping("/detail")
    public R<QuestionDetailVo> detail(Long questionId) {
        return questionService.detail(questionId);
    }


    @PutMapping("/edit")
    public R<Void> edit(@RequestBody QuestionEditDto questionEditDto) {
        return toR(questionService.edit(questionEditDto));
    }

    @DeleteMapping("/del")
    public R<Void> del(Long questionId){
        return toR(questionService.del(questionId));
    }


    @PostMapping("/desc/tmpImg/upload")
    public R<OSSResult> questionDescTmpImgUpload(@RequestBody MultipartFile file) {
        return R.ok(fileService.tmpImgUpload(file));
    }

    @GetMapping("/getAllQuestionTag")
    public R<List<QuestionTagVo>> getAllQuestionTag() {
        return R.ok(questionTagService.getAllQuestionTags());
    }
}
